<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form>
        <input type="text" name="user">
        <input type="password" name="pass">
        <input type="file" name="myfile">
        <input type="submit" value="提交" name="">
    </form>
    <script>
        // 服务器请求在index2.js中
        document.forms[0].onsubmit = function(e){
            e.preventDefault();
            var data = new FormData(this);
            var xhr = new XMLHttpRequest();
            xhr.open("post","/postOne"); //配置请求信息
            // 关于传递数据的数据格式
            // ("Content-Type","application/x-www-form-urlencoded")
            // 属性名=属性值&属性名=属性值 
            
            //  默认的数据格式form-data数据格式
            //  ("Content-Type","multipart/form-data")
            xhr.send(data);
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4) {
                    console.log(xhr.responseText);
                }
            } 
        }
    </script>
</body>
</html>